package com.niannian.util;

import java.io.File;

import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.RemoteViews;

import com.niannian.MyApplication;
import com.niannian.imgCache.core.BitmapDecoder;
import com.niannian.util.network.QHttpUtil;

public class NotificationHead extends AsyncTask<String, Integer, String> {
	private byte[] data;
	int viewId = 0;
	RemoteViews rv;
	@SuppressWarnings("unused")
	public NotificationHead(int viewId,RemoteViews rv) {
		super();
		this.viewId = viewId;
		this.rv=rv;
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
	}

	@Override
	protected void onProgressUpdate(Integer... values) {
		super.onProgressUpdate(values);
		// LordImage.setProgress(values[0]);
	}

	@Override
	protected String doInBackground(String... params) {
		Log.i("doInBackground", params[0]);
		data = QHttpUtil.download_image1(params[0]);
		return null;
	}

	@Override
	protected void onPostExecute(String uri) {
		super.onPostExecute(uri);
		try {
			Bitmap showBitmap = null;

			if (data != null) {
				showBitmap = BitmapDecoder.decodeSampledBitmapFromByteArray(data, 0, data.length, 100, 100);
				rv.setImageViewBitmap(viewId, showBitmap);
			} else {
				Log.w("onPostExecute", "download null data for display image");
			}
			String savpic = MyApplication.FILE_PATH_TEMP + MD5Util.encode(uri) + FileUtils.getImageFileExtension(uri);
			BitmapUtil.saveBmp(showBitmap, savpic, 100);

			if (!new File(savpic).exists()) {
				// Common.tip(this, "图片保存失败");
			}

			// DownloadingMap.remove(p);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
